package com.caiwangdai.app.ui.me

import android.content.Context
import android.content.Intent
import com.caiwangdai.app.R
import com.caiwangdai.app.backend.RetrofitHome
import com.caiwangdai.app.backend.observer.OnDataV2Listener
import com.caiwangdai.app.backend.rx.RxSchedulers
import com.caiwangdai.app.bean.UserIdentityB
import com.caiwangdai.app.bean.base.NormalResponseB
import com.caiwangdai.app.origin.BaseActivity
import com.caiwangdai.app.origin.ToolBarManager
import com.caiwangdai.app.widget.MultiplyStateViewWM
import kotlinx.android.synthetic.main.activity_identity_info.*

//身份信息
class IdentityInfoActivity : BaseActivity() {
    override fun getLayoutResID() = R.layout.activity_identity_info

    companion object {
        fun newInstance(context: Context): Intent {
            val intent = Intent(context, IdentityInfoActivity::class.java)
            return intent
        }
    }

    override fun initData() {
        getUserIdentityInfo()
    }

    override fun initView() {
        ToolBarManager.with(this, WMContent)
                .setTitle("身份信息")
                .setNavigationIcon(R.drawable.ic_nav_arrow_white)


    }
    private fun getUserIdentityInfo() {
        RetrofitHome.getUserApi()
                .getUserIdentityInfo()
                .compose(RxSchedulers.toMain())
                .subscribe(object : OnDataV2Listener<UserIdentityB>(this, swipe_refresh, true) {

                    override fun onSuccess(value: NormalResponseB<UserIdentityB>) {
                        if (value.data?.info?.isAuth == 0) {
                            multiView.setViewState(MultiplyStateViewWM.VIEW_STATE_EMPTY)
                            return
                        }
                        val data = value.data?.info
                        //name
                        tv_name.text = data?.name
                        //idCard
                        tv_code.text = data?.idcard
                    }
                })
    }
}
